<template>
	<view>
		<view class="" v-if="arr.length > 0">
			<view v-for="(it,i) in arr" :key="i" class="list">
				<view>
					<image style="width: 98rpx;height: 98rpx;" :src="imgUrl + 'massage-icon.png'"></image>
				</view>
				
				<view style="width: 100%;padding-left: 26rpx;border-bottom: 1rpx solid #EFEFEF;padding-top: 20rpx;padding-bottom: 20rpx;">
					<view style="display: flex;justify-content: space-between;align-items: center;">
						<view style="font-size: 34rpx;color: #333333;">{{it.title}}</view>
						<view style="font-size: 22rpx;color: #868989;">{{it.time}}</view>
					</view>
					<view style="padding-top: 20rpx;font-size: 28rpx;color: #999999;">
						{{it.content}}
					</view>
				</view>
			</view>
			<view class="finished">—— 没有更多了 ——</view>
		</view>
		
		<view class="zanwu-data"  v-if="arr.length == 0">
			暂无消息
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				imgUrl: 'https://syxiyi.oss-cn-shenzhen.aliyuncs.com/frontend/img/',
				arr:[],
				page: 1,
				total: false
			}
		},
		onLoad() {
			let loginstatus = uni.getStorageSync('token');
			if(loginstatus)
			{
			this.getNews()
			this.getYidus()

			}
		},
		methods: {
			getNews() {
				this.$ajaxRequest.get(this.baseUrl + 'shop/member/news', {
					page: this.page,
					size: 10
				}, true).then(res => {
					console.log(res)
					if (res.data.code == 200) {
						if (this.page == 1) {
							this.arr = res.data.data
						} else {
							this.arr.push.apply(this.arr, res.data.data)
						}
						if (res.data.data.length < 10) this.total = true
						
					} else {
						uni.showToast({
							title:res.data.msg,
							icon:'none'
						})
					}
				})
			},
			// 消息已读
			getYidus() {
				this.$ajaxRequest.get(this.baseUrl + 'shop/member/setNews', {}, false).then(res => {
					if (res.data.code == 200) {
						console.log(res)
					} else {
						uni.showToast({
							title:res.data.msg,
							icon:'none'
						})
					}
				})
			}
		},
		onReachBottom() {
			if (this.total) return false
			this.page++
			this.getNews()
		},
	}
</script>

<style>
	.list{
		display: flex;
		align-items: center;
		padding: 0rpx 30rpx;
	}
</style>
